package cn.uin.infrastructure.adapter.repository;

import cn.uin.domain.oss.adapter.repository.IFileRepository;
import cn.uin.domain.oss.model.entity.HomeAttachmentEntity;
import cn.uin.infrastructure.dao.HomeAttachmentDao;
import cn.uin.infrastructure.dao.po.HomeAttachment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @ClassName FileRepository
 * @Description:类描述
 * @Author: Administrator
 * @CreateDate: 2025/11/4 17:41
 * @Version: 1.0
 */
@Slf4j
@Repository
public class FileRepository implements IFileRepository {

	@Resource
	private HomeAttachmentDao homeAttachmentDao;

	@Override
	public HomeAttachmentEntity saveHomeAttachment(HomeAttachmentEntity homeAttachmentEntity) {
		HomeAttachment homeAttachment = HomeAttachment.builder()
				.fileName(homeAttachmentEntity.getFileName())
				.fileType(homeAttachmentEntity.getFileType())
				.logicPath(homeAttachmentEntity.getLogicPath())
				.size(homeAttachmentEntity.getSize())
				.createUserId(homeAttachmentEntity.getCreateUserId())
				.updateUserId(homeAttachmentEntity.getUpdateUserId())
				.build();
		homeAttachmentDao.insert(homeAttachment);
		homeAttachmentEntity.setId(homeAttachment.getId());
		return homeAttachmentEntity;
	}

	@Override
	public HomeAttachmentEntity queryById(Long fileId) {
		HomeAttachment homeAttachment = homeAttachmentDao.queryById(fileId);
		return HomeAttachmentEntity.builder()
				.id(homeAttachment.getId())
				.fileName(homeAttachment.getFileName())
				.fileType(homeAttachment.getFileType())
				.logicPath(homeAttachment.getLogicPath())
				.size(homeAttachment.getSize())
				.createUserId(homeAttachment.getCreateUserId())
				.createTime(homeAttachment.getCreateTime())
				.build();
	}
}
